package cc.czlee.cloud.zuul.filters;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/*
 * Create by Colbert on 2019-05-02
 *
 * Copyright (C) 2019 chuanzhigo@gmail.com.
 */
@Component
public class PreFilter2 extends ZuulFilter {

    private Logger logger = LoggerFactory.getLogger(PreFilter2.class);

    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() {
        return 1;
    }

    @Override
    public boolean shouldFilter() {
        /*
         * 这里可以判断当前面的过滤器没通过，这里不再过滤执行
         * 如果返回true,则不考虑前面过滤器的执行结果，依旧执行
         */
        RequestContext requestContext = RequestContext.getCurrentContext();
        return requestContext.sendZuulResponse();
        //return true;
    }

    @Override
    public Object run() throws ZuulException {
        logger.warn("pre filter 2 run");
        return null;
    }
}
